package expression;

import java.util.LinkedList;

public class FnArithDivide extends Fn implements FnNumber, FnString {

	@Override
	protected boolean isAcceptableChild(Fn fn) {
		return (fn instanceof FnNumber);
	}
	
	@Override
	protected boolean isAcceptableParam(Object o) {
		return (o instanceof Number);
	}

	@Override
	public int getNParam() {
		return 2;
	}

	@Override
	protected int precedence() {
		return 6;
	}

	@Override
	protected Object value(LinkedList<Object> param) {
		Double out = new Double(0);
		int i = 0;
		for (Object operand : param) {
			if(i == 0)
				out += ((Number) operand).doubleValue();
			else
				out /= ((Number) operand).doubleValue();
			i++;
		}
		return out;
	}

	@Override
	public String symbol() {
		return "/";
	}

	@Override
	protected String[] notation() {
		return new String[]
		{ "", " / ", "" };
	}

}
